package ru.lenwp.context;

import ru.lenwp.dao.AccountDao;
import ru.lenwp.dao.UserDao;
import ru.lenwp.model.Admin;
import ru.lenwp.model.Client;
import ru.lenwp.model.User;
import ru.lenwp.util.GenerationNumber;

import java.sql.Connection;

/**
 * Created by Lenar on 16.07.2014.
 */
public class Context {

    private UserDao userDao;

    private AccountDao accountDao;

    public AccountDao getAccountDao() {
        return accountDao;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    private Admin admin;

    private User currentUser;

    private GenerationNumber accountGn = new GenerationNumber();

    public User getCurrentUser(){
        return currentUser;
    }

    public void setCurrentUser(User user){
        this.currentUser = user;
    }

    private Connection conn;

    public Connection getConn() {
        return conn;
    }

    public long nextAccountId(){
        return accountGn.nextValue();
    }

    public Context(Connection conn){
        this.conn = conn;
        userDao = new UserDao(conn);
        accountDao = new AccountDao(conn, userDao);
        admin = new Admin();
        admin.setLogin("root");
        admin.setPassword("admin");
    }
}
